<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
  SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟
  String nowDate =  sdf.format(new Date());
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

<html>
  <head>
    <base href="<%=basePath%>">
    <link rel="icon" href="<%=basePath%>plug_in/images/icon/top.ico" type="image/x-icon"/>
    <title>天津考勤同步</title>
    <script src="<%=basePath%>plug_in/js/jquery-1.11.1.min.js"></script>
    <%--引入时间控件--%>
    <script language="javascript" type="text/javascript" src="<%=basePath%>plug_in/My97DatePicker/WdatePicker.js"></script>



    <style type="text/css">
      #maindiv{
        margin: 0 auto;
        width: 350px;
        text-align:center;
        border:2px solid #a1a1a1;
        padding:10px 40px;
        background:#dddddd;
        border-radius:25px;
        -moz-border-radius:25px; /* 老的 Firefox */
      }

    </style>
  </head>
  <body>
<div id="maindiv" >
  <img src="<%=basePath%>plug_in/images/bg.png"/>

  <h2> 天津考勤同步</h2>

  选择时间：<input style="width: 80px;"
         title="修改时间"
         value="<%=nowDate%>"
         id="searchdate1"
         onclick="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" /> &nbsp;

  <button id="tj" onclick="tbkq()">点击同步考勤到OA</button> <br/><br/>

  <hr/>


  <span style="font-size: 12px;">@2003-2019 By Mine Loader Java Team.</span>
</div>

  </body>

  <script type="text/javascript" >
    $(function () {
        var msg = "${msg}";
        if(msg){
            $("#msg").text(msg);
        }
    })

   function tbkq() {
       var searchdate1 = $("#searchdate1").val();
       if(searchdate1){
           var year = parseInt(searchdate1.split("-")[0]);
           var month = parseInt(searchdate1.split("-")[1]);
           var day = parseInt(searchdate1.split("-")[2]);
           if(confirm("是否要同步 "+year+" / "+month+" / "+ day+" 的考勤数据?")){
               $("#tj").val("同步中请稍后……");
               $.ajax({
                   url:"http://192.168.10.244:8080/ml/api/kq/tj/date",
                   type:"POST",
                   cache:false,
                   async:false,
                   dataType:"json",
                   data:{"year":year,"month":month,"day":day},
                   success:function(data){
                       if(data){
                           alert(data.msg);
                           $("#tj").text("点击同步考勤到OA");
                       }
                   },
                   error:function(data){
                       $("#tj").text("系统异常，同步失败！请联系管理员！");
                       alert("系统异常，同步失败！请联系管理员！");
                   }
               });
           }
       }
   }
  </script>
</html>
